using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace FluidDemo.Model
{
    public class Particle
    {
        public Particle()
        {
            Mass = 0.1f;
        }

        public Particle(Vector2 position, float mass)
        {
            Previous = Position = position; Mass = mass;
        }

        public readonly List<ParticleRelation> Links = new List<ParticleRelation>();

        public Color Color = Color.Transparent;

        public Vector2 Position = Vector2.Zero;

        public Vector2 Previous = Vector2.Zero;

        public Vector2 Real = Vector2.Zero;

        public Vector2 Velocity = Vector2.Zero;

        public float Energy = 1;

        public Vector2 Influence = Vector2.Zero;

        public void Update()
        {
            Real = Position;
            Vector2 v = Position - Previous + Influence;
            if (v.LengthSquared() > 6 * 6)
            {
                v.Normalize();
                v *= 6;
            }
            Velocity = v;
            Influence = Vector2.Zero;
        }

        public Vector2 Force = Vector2.Zero;

        Vector2 acceleration = Vector2.Zero;

        public Vector2 Acceleration
        {
            get { return mass != 0 ? Force * oneOverMass : Vector2.Zero; }
        }

        public float Radius = 1;

        float mass = 1;

        public float Mass
        {
            get { return mass; }
            set
            {
                mass = value;
                oneOverMass = mass != 0 ? 1 / mass : 0;
            }
        }

        float oneOverMass = 1;

        public float OneOverMass
        {
            get { return oneOverMass; }
        }
    }
}
